package org.mapki;

import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class RouteOverlay extends Overlay { 

private int mRadius=6;
private int pRadius=3;

private int defaultColor = 999;

private List<GeoPoint> pList;



public RouteOverlay(List<GeoPoint> pList){
	this.pList = pList;
}



@Override
public boolean draw (Canvas canvas, MapView mapView, boolean shadow, long when) {
    Projection projection = mapView.getProjection();
    GeoPoint gp1, gp2;
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    Point point = new Point();
    Point point2 = new Point();
    
    for(int i=0; i<pList.size()-1; i++){
        gp1 = pList.get(i);
        gp2 = pList.get(i+1);
        projection.toPixels(gp1, point);
        projection.toPixels(gp2, point2);
        //start of the path
        if(i==0) {
            if(defaultColor==999)
            paint.setColor(Color.BLACK); // Color.BLUE
            else
            paint.setColor(defaultColor);
            RectF oval=new RectF(point.x - mRadius, point.y - mRadius,
            point.x + mRadius, point.y + mRadius);
            // start point
            canvas.drawOval(oval, paint);
        }
        //end of the path
        if(i==pList.size()-2) {
            /* the last path */

            if(defaultColor==999)
                paint.setColor(Color.BLACK);  // Color.GREEN
            else
                paint.setColor(defaultColor);

            paint.setStrokeWidth(5);
            paint.setAlpha(defaultColor==Color.parseColor("#6C8715")?220:120);
            canvas.drawLine(point.x, point.y, point2.x,point2.y, paint);
            RectF oval=new RectF(point2.x - mRadius,point2.y - mRadius,
            point2.x + mRadius,point2.y + mRadius);
            /* end point */
            paint.setAlpha(255);
            canvas.drawOval(oval, paint);
        }
        //elements of the path
        if(defaultColor==999)
        paint.setColor(Color.RED);
        else
        paint.setColor(defaultColor);
        
        paint.setStrokeWidth(5);
        paint.setAlpha(defaultColor==Color.parseColor("#6C8715")?220:120);
        canvas.drawLine(point.x, point.y, point2.x,point2.y, paint);
        RectF oval=new RectF(point2.x - pRadius,point2.y - pRadius,
                point2.x + pRadius,point2.y + pRadius);
        canvas.drawOval(oval, paint);
        
        
        
    }
    return super.draw(canvas, mapView, shadow, when);
}

}